/**
 * Desc: Display a clock counting up.
 * Copyright: Stephen P. Tetley
 * License: BSD3
 */

package swidgets;


import processing.core.*;
import controlP5.*;


/**
 * Display a clock counting up.
 */

public class SWDisplayClock {
	
	protected ControlTimer ct;
	protected Textlabel tx;
	PFont fnt;

	// loadFont is accessible via PApplet...
	
	public SWDisplayClock (final ControlP5 theControlP5, final PApplet thePApplet) {
		fnt = thePApplet.loadFont("CourierNewPS-BoldMT-24.vlw");
		tx = new Textlabel(theControlP5,"--",200,200);
		tx.setFont(fnt);
		ct = new ControlTimer ();
		ct.setSpeedOfTime(1);
	}
		  
	public SWDisplayClock ( final ControlP5 theControlP5, PFont ft ) {
		fnt = ft;
		tx = new Textlabel(theControlP5,"--",200,200);
		tx.setFont(fnt);
		ct = new ControlTimer ();
		ct.setSpeedOfTime(1);
	}
		  
	public void render () {
		int h, m, s;
		ct.update();
		h = ct.hour();
		m = ct.minute();
		s = ct.second();
		tx.setValue(((h < 10) ? "0" : "") + h + ":" +
					((m < 10) ? "0" : "") + m + ":" +
					((s < 10) ? "0" : "") + s );
		
		tx.draw();
	}
		  
	public void reset () {
		ct.reset(); 
	}
}

